package edu.lhh;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.lhh.dao.scoretypedao;
import edu.lhh.model.scoretype;

/**
 * Servlet implementation class scoreupdata
 */
@WebServlet("/scoreupdata")
public class scoreupdata extends HttpServlet {
	private static final long serialVersionUID = 1L;
	scoretypedao dao = new scoretypedao();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public scoreupdata() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String id = request.getParameter("id");
		try {
			scoretype tp = dao.findbyid(id);
			request.setAttribute("ups", tp);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getRequestDispatcher("upScore.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		scoretype tp = new scoretype();
		tp.setId(request.getParameter("id"));
		tp.setMath(Integer.parseInt(request.getParameter("math")));
		tp.setEnglish(Integer.parseInt(request.getParameter("eng")));
		tp.setPe(Integer.parseInt(request.getParameter("pe")));
		tp.setIndex(Integer.parseInt(request.getParameter("index")));
		dao.updata(tp);
		response.sendRedirect("scoresuccess.jsp");
		
		
		
	}

}
